#include "aewaveinfotab.h"
#include "aewavefeature.h"
#include <QHeaderView>
#include <QHBoxLayout>
#include <QString>

AEWaveInfoTab::AEWaveInfoTab(QWidget *parent)
    : MapInfoTab(parent)
    , m_aeWaveFeature(std::make_shared<AEWaveFeature>())
    , m_pChartBox(nullptr)
    , m_pChartData(nullptr)
    , m_pMainLayout(nullptr)
    , m_pLayout(nullptr)
{
    initUI();
}

AEWaveInfoTab::~AEWaveInfoTab()
{
    // UI元素会随父对象自动删除
}

void AEWaveInfoTab::initUI()
{
    m_pMainLayout = new QHBoxLayout(this);
    m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    m_pMainLayout->setSpacing(0);

    // 添加Feature组件的UI
    m_aeWaveFeature->initUI(this);
    addFeature(m_aeWaveFeature);

    // 创建图表数据区域
    m_pChartBox = new QGroupBox("AE波形图谱数据", this);
    m_pChartData = new QTextEdit(m_pChartBox);
    m_pChartData->setReadOnly(true);
    m_pChartData->setMinimumWidth(300);
    m_pChartData->setMinimumHeight(400);

    QVBoxLayout* pChartLayout = new QVBoxLayout(m_pChartBox);
    pChartLayout->addWidget(m_pChartData);
    pChartLayout->setContentsMargins(10, 10, 10, 10);

    m_pLayout = new QHBoxLayout();
    m_pLayout->addWidget(m_pChartBox);
    m_pLayout->setContentsMargins(0, 0, 0, 0);

    m_pMainLayout->addLayout(m_pLayout);
}

void AEWaveInfoTab::setDataTypeCode(uint8_t code)
{
    // 数据会通过特性组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setDataTypeCode(code);
    }
}

void AEWaveInfoTab::setDataLength(int32_t length)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setDataLength(length);
    }
}

void AEWaveInfoTab::setCreateTime(const QString& time)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setCreateTime(time);
    }
}

void AEWaveInfoTab::setChartProperty(const DataSpecificationGW::SpectrumCharacter& property)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setChartProperty(property);
    }
}

void AEWaveInfoTab::setDeviceName(const QString& name)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setDeviceName(name);
    }
}

void AEWaveInfoTab::setDeviceCode(const QString& code)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setDeviceCode(code);
    }
}

void AEWaveInfoTab::setMeasurementName(const QString& name)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setMeasurementName(name);
    }
}

void AEWaveInfoTab::setMeasurementCode(const QString& code)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setMeasurementCode(code);
    }
}

void AEWaveInfoTab::setChannelFlag(int64_t flag)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setChannelFlag(flag);
    }
}

void AEWaveInfoTab::setDataType(uint8_t type)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setDataType(type);
    }
}

void AEWaveInfoTab::setAmplitudeUnit(uint8_t unit)
{
    m_aeWaveFeature->setAmplitudeUnit(unit);
}

void AEWaveInfoTab::setAmplitudeLowerLimit(float lowerLimit)
{
    m_aeWaveFeature->setAmplitudeLowerLimit(lowerLimit);
}

void AEWaveInfoTab::setAmplitudeUpperLimit(float upperLimit)
{
    m_aeWaveFeature->setAmplitudeUpperLimit(upperLimit);
}

void AEWaveInfoTab::setUltrasonicSensorType(float type)
{
    m_aeWaveFeature->setUltrasonicSensorType(type);
}

void AEWaveInfoTab::setDataPointCount(int32_t count)
{
    m_aeWaveFeature->setDataPointCount(count);
}

void AEWaveInfoTab::setSamplingRate(int64_t rate)
{
    m_aeWaveFeature->setSamplingRate(static_cast<float>(rate));
}

void AEWaveInfoTab::setDischargeTypeProbability(const QString& probability)
{
    m_aeWaveFeature->setDischargeTypeProbability(probability);
}

void AEWaveInfoTab::setReservedData(const QByteArray& byte)
{
    // 数据将通过Feature组件显示
    if (m_aeWaveFeature) {
        m_aeWaveFeature->setReservedData(byte);
    }
}

void AEWaveInfoTab::setAEWaveChartData(const QByteArray& data)
{
    m_pChartData->setText(data.toHex());
}
